package com.ts.simplemusic;

import java.util.ArrayList;
import java.util.List;

public class MusicHelper {

    /**
     * 播放列表
     */
    private List<Music> mMusicList = new ArrayList<>();

    /**
     * 当前播放音乐下标
     */
    private int currentPosition = -1;

    /**
     * 播放状态
     */
    private boolean mPlayingState;

    private static class SingletonHolder {
        private static final MusicHelper mMusicHelper = new MusicHelper();
    }

    public static MusicHelper getInstance() {
        return SingletonHolder.mMusicHelper;
    }

    /**
     * 上一首
     */
    public int prev() {
        if (currentPosition > 0) {
            currentPosition -= 1;
            return 0;
        } else {
            return -1;
        }
    }

    /**
     * 下一首
     */
    public int next() {
        if (currentPosition < (mMusicList.size() - 1)) {
            currentPosition += 1;
            return 0;
        } else {
            return -1;
        }
    }

    public boolean isPlayingState() {
        return mPlayingState;
    }

    public void setPlayingState(boolean playingState) {
        mPlayingState = playingState;
    }

    public List<Music> getMusicList() {
        return mMusicList;
    }

    public void setMusicList(List<Music> musicList) {
        mMusicList = musicList;
    }

    public int getCurrentPosition() {
        return currentPosition;
    }

    public void setCurrentPosition(int currentPosition) {
        this.currentPosition = currentPosition;
    }

    public Music getCurrentMusic() {
        if (currentPosition <= (mMusicList.size() - 1) && currentPosition >= 0) {
            return mMusicList.get(currentPosition);
        } else {
            return null;
        }
    }
}
